package org.springcloud.wisdom.amusement.service.serviceimp;

import org.springcloud.wisdom.amusement.dao.LoginDao;
import org.springcloud.wisdom.amusement.dao.Team_StudentDao;
import org.springcloud.wisdom.amusement.entity.Admin;
import org.springcloud.wisdom.amusement.entity.FullStudent;
import org.springcloud.wisdom.amusement.entity.Student;
import org.springcloud.wisdom.amusement.entity.Team_Student;
import org.springcloud.wisdom.amusement.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginImpServiceImp implements ILoginService {
    @Autowired
    LoginDao loginDao;
    @Autowired
    Team_StudentDao teamStudentDao;
    @Override
    public Admin adminLogin(String account, String password) {
        if (account.trim().length()==0 || account==null){
            return null;
        }
        if (password.trim().length()==0 || password==null){
            return  null;
        }
        return loginDao.getAdmin(account, password);
    }

    @Override
    public Student studentLogin(String account, String password) {
        if (account.trim().length()==0 || account==null){
            return null;
        }
        if (password.trim().length()==0 || password==null){
            return  null;
        }
        return loginDao.getStudent(account, password);
    }

    @Override
    public FullStudent teamStudentLogin(Student student) {
        if (student == null) {
            return null;
        }
        Team_Student teamStudent1 = teamStudentDao.selectTeamStudent(student.getSid());
        if (teamStudent1 != null) {
            FullStudent fullStudent = new FullStudent();
            fullStudent.setAdsno(student.getAdsno());
//            fullStudent.setId(teamStudent1.getId());
            fullStudent.setSid(student.getSid());
            fullStudent.setIdentify(student.getIdentify());
            fullStudent.setSname(student.getSname());
            fullStudent.setGender(student.getGender());
            fullStudent.setAddress(student.getAddress());
            fullStudent.setSpassword(student.getAdpass());
            fullStudent.setSmail(student.getMail());
            fullStudent.setPhone(student.getPhone());
            fullStudent.setSdept(student.getDept());
            fullStudent.setTalent(student.getTalent());
            String team = teamStudentDao.selectTeamName(teamStudent1.getTeamid());
            fullStudent.setTeam(team);
            fullStudent.setTeamid(teamStudent1.getTeamid());
            String teamRole = null;
            if (teamStudent1.getRole() == 0) {
                teamRole = "成员";
            }
            if (teamStudent1.getRole() == 1) {
                teamRole = "社长";
            }
            if (teamStudent1.getRole() == 2) {
                teamRole = "外联部长";
            }
            fullStudent.setTeamRole(teamRole);
            return fullStudent;
        } else {
            return null;
        }
    }
}
